efform_onload = function ()
{
	
};  

button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCG98","query");
}

button_insert_onclick = function (){
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdVirtualdate = grid.getCellValueByColumnName(rows[i], "fdVirtualdate"); // 填报日期
	    if(fdVirtualdate > now()){
			EFAlert("填报日期大于当前日期");
			return;
		}
	    var time = new Date((now()).replace(/-/g, "/")) - new Date((fdVirtualdate).replace(/-/g, "/"));
	    var day = parseFloat(time) / (1000*60*60*24);//与当前日期相差天数
	    if(day >30)
	    	{
	    	EFAlert("只能新增一个月内的记录");
			return;
	    	}
	}

	efgrid.submitForm("ef_grid_result", "ZM", "ZMCG98", "insert",true);
}

button_update_onclick = function (){  
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdVirtualdate = grid.getCellValueByColumnName(rows[i], "fdVirtualdate"); // 填报日期	
	    if(fdVirtualdate > now()){
			EFAlert("填报日期大于当前日期");
			return;
		}
	    var time = new Date((now()).replace(/-/g, "/")) - new Date((fdVirtualdate).replace(/-/g, "/"));
	    var day = parseFloat(time) / (1000*60*60*24);//与当前日期相差天数
	    if(day >30)
	    	{
	    	EFAlert("只能修改一个月内的记录");
			return;
	    	}
	}
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCG98","update",true); 
}

button_delete_onclick = function() {
	var grid=isSelected("ef_grid_result");
	if (grid == 0)  return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdVirtualdate = grid.getCellValueByColumnName(rows[i], "fdVirtualdate"); // 填报日期
	    var time = new Date((now()).replace(/-/g, "/")) - new Date((fdVirtualdate).replace(/-/g, "/"));
	    var day = parseFloat(time) / (1000*60*60*24);//与当前日期相差天数
	    if(day >30)
	    	{
	    	EFAlert("只能删除一个月内的记录");
			return;
	    	}
	}
	EFConfirm('你确认要删除吗?', '确认框',function(r) {
		if (r)efgrid.submitForm("ef_grid_result", "ZM", "ZMCG98","delete", true);
	});
}

efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {
		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdVirtualdate", getVirtualdate());		
		}
	}
	for (var i = 0; i < rows.length; i++) {
		grid.getBlockData().setCell(rows[i], "fdKeyId", "");
	}
}

now = function(){
	//当前日期
	var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    if(month > 12) {
    	year = year + 1;				//下一年
    	month = 1;						//第一个月
    }
    if(month < 10) {
    	month = "0" + month;
    }
    var day = now.getDate();            //日 
    var clock = year + "-" + month + "-";
    if(day < 10) clock += "0";
    clock += day + " "; 
    return clock;
}

button_print_onclick = function() {
	var fdVirtualDate = $('#inqu_status-0-fdVirtualdate').val();
    var year = fdVirtualDate.substr(0,4);
    var month = fdVirtualDate.substr(5,2);
    var day = fdVirtualDate.substr(8,2);
    var year_month = fdVirtualDate.substr(0,7);
    var last_year = year - 1;
    var last_fdVirtualDate = last_year + "-" + month + "-" + day;
    var last_yearmonth = last_year + "-" + month;
    if (month == "01" || month == "02" || month == "03"){
    	var startmonth = "01";
    	var endmonth = "03";
    }
    if(month == "04" || month == "05" || month == "06") {
    	var startmonth = "04";
    	var endmonth = "06";
    }
    if (month == "07" || month == "08" || month == "09"){
    	var startmonth = "07";
    	var endmonth = "09";
    }
    if (month == "10" || month == "11" || month == "12"){
    	var startmonth = "10";
    	var endmonth = "12";
    }
	// 取报表参数
	var param = [];
	param.virtualdate =fdVirtualDate;
	param.year =year;
	param.year_month = year_month;
	param.last_year = last_year;
	param.last_virtualdate = last_fdVirtualDate;
	param.startmonth = startmonth;
	param.endmonth = endmonth;
	param.last_yearmonth = last_yearmonth;
	var reportEname = "SZMDGSDDRB";
	try {
		previewReport(reportEname,param);
	} catch (e) {
		alert("控件加载失败，请确认控件是否正确安装并将本网站设为信任地址");
	}
}

button_printxun_onclick = function() {
	var fdVirtualDate = $('#inqu_status-0-fdVirtualdate').val();
    var year = fdVirtualDate.substr(0,4);
    var month = fdVirtualDate.substr(5,2);
    var day = fdVirtualDate.substr(8,2);
    var year_month = fdVirtualDate.substr(0,7);
    var last_year = year - 1;
    var last_fdVirtualDate = last_year + "-" + month + "-" + day;
    var last_yearmonth = last_year + "-" + month;
    if(day>=1 && day<=10){
    	var xun = "上旬";
    	var startday ="01";
    	var endday ="10";
    	var enddate =year_month + "-" + "10";
    	var last_enddate =last_yearmonth + "-" + "10";
    }
    if(day>=11 && day<=20){
    	var xun = "中旬";
    	var startday = "11";
    	var endday = "20";
    	var enddate =year_month + "-" + "20";
    	var last_enddate =last_yearmonth + "-" + "20";
    }
    if(day>=21 && day<=31){
    	var xun = "下旬";
    	var startday = "21";
    	var endday = "31";
    	var enddate =year_month + "-" + "31";
    	var last_enddate =last_yearmonth + "-" + "31";
    }

	// 取报表参数
	var param = [];
	param.virtualdate =fdVirtualDate;
	param.year =year;
	param.year_month = year_month;
	param.last_year = last_year;
	param.last_virtualdate = last_fdVirtualDate;
	param.startday = startday;
	param.endday = endday;
	param.xun = xun;
	param.last_yearmonth = last_yearmonth;
	param.enddate = enddate;
	param.last_enddate = last_enddate;
	var reportEname = "SZMDGSDDXB";
	try {
		previewReport(reportEname,param);
	} catch (e) {
		alert("控件加载失败，请确认控件是否正确安装并将本网站设为信任地址");
	}
}

button_printmonth_onclick = function() {
	var fdVirtualDate = $('#inqu_status-0-fdVirtualdate').val();
    var year = fdVirtualDate.substr(0,4);
    var month = fdVirtualDate.substr(5,2);
    var day = fdVirtualDate.substr(8,2);
    var year_month = fdVirtualDate.substr(0,7);
    var last_year = year - 1;
    var last_fdVirtualDate = last_year + "-" + month + "-" + day;
    var last_yearmonth = last_year + "-" + month;
    if (month == "01" || month == "02" || month == "03"){
    	var startmonth = "01";
    	var endmonth = "03";
    	var quarterstart = year + "-" + "01" + "-" + "01";
    	var quarterend = year + "-" + "03" + "-" + "31";
    }
    if(month == "04" || month == "05" || month == "06") {
    	var startmonth = "04";
    	var endmonth = "06";
    	var quarterstart = year + "-" + "04" + "-" + "01";
    	var quarterend = year + "-" + "06" + "-" + "30";
    }
    if (month == "07" || month == "08" || month == "09"){
    	var startmonth = "07";
    	var endmonth = "09";
    	var quarterstart = year + "-" + "07" + "-" + "01";
    	var quarterend = year + "-" + "09" + "-" + "30";
    }
    if (month == "10" || month == "11" || month == "12"){
    	var startmonth = "10";
    	var endmonth = "12";
    	var quarterstart = year + "-" + "10" + "-" + "01";
    	var quarterend = year + "-" + "12" + "-" + "31";
    }
	// 取报表参数
	var param = [];
	param.virtualdate =fdVirtualDate;
	param.year =year;
	param.year_month = year_month;
	param.last_year = last_year;
	param.last_virtualdate = last_fdVirtualDate;
	param.startmonth = startmonth;
	param.endmonth = endmonth;
	param.last_yearmonth = last_yearmonth;
	param.quarterstart = quarterstart;
	param.quarterend = quarterend;
	var reportEname = "SZMDGSDDYB";
	try {
		previewReport(reportEname,param);
	} catch (e) {
		alert("控件加载失败，请确认控件是否正确安装并将本网站设为信任地址");
	}
}